//require('jsonwebtoken');
//验证数据库中的用户相关内容
const User = {
	//查询用户手机号  //option传过来的值  option.userTel传过来的电话号码
	queryUserTel( option ){		 
		return 'select * from user where tel = '+option.userTel+'';
			//可返回多条数据
	},
	//查询密码
	queryUserPwd( option ){
		return 'select * from user where (tel = '+option.userTel+') and pwd = '+option.userPwd+'';
	},//return 数据
	//新增用户
	/* inserData( option ){

		let userTel = option.userTel;//return sql语句 
		let userPwd=option.userPwd||option.userTel;
		//引入token包
		let jwt = require('jsonwebtoken');
		//用户信息
		//let payload={userTel};//用{}围着意味着什么？//手机号是唯一
		let payload = {tel:userTel};
		//口令
		let secret='BORA';
		//获取时间 过期时间为100天
		let overdue = new Date()+8640000;
		//生成token jwt.sign( 用户信息 , 口令 , 过期时间)
        let token = jwt.sign(payload,secret);
		//console.log(token);
		//console.log("88888888888888888888888888888888888888");
		return 'insert into user (tel,pwd,imgUrl,nickName,token) values ("'+userTel+'","'+userPwd+'","/images/user.jpeg","'+userTel+'","'+token+'")';//"'+userPwd+'" 这样

	} */
	inserData( option ){
        
		let userTel = option.userTel;
		let userPwd = option.userPwd  || '666666';
        //引入token包
        let jwt = require('jsonwebtoken');
        //用户信息
		
        let payload = {tel:userTel};
        //口令
        let secret = 'xiaoluxian';
        //生成token
        //let token = jwt.sign(payload,secret);这个是没有设置过期时间的
		//下面设置过期时间
		let token = jwt.sign(payload,secret,{
			expiresIn:600000//秒  60  '1h'
		});
		//let jwt = require('jsonwebtoken');//不知道要不要用/上面有了
		//let tokenObj = jwt.decode(token);
        //let tokenObj = jwt.decode(token);
		//console.log(tokenObj);
		//这个可以解出token的过期时间exp 还有 iat当前时间

		return 'insert into user (tel,pwd,imgUrl,nickName,token) values ("'+userTel+'","'+userPwd+'","/images/user.jpeg","'+userTel+'","'+token+'")';
	}
}
//exports抛出去  ueer=》const User
exports = module.exports = User;
//暴露User